package code._13io.bytestream.in;

import java.io.FileInputStream;
import java.io.IOException;

public class Demo3 {
    public static void main(String[] args) throws IOException {
        FileInputStream in = new FileInputStream("a.txt");
        readWhile2(in);

        byte[] bytes = new byte[1024];
        int readCount;
        while((readCount=in.read(bytes))!=-1){
            System.out.println(new String(bytes,0,readCount));
        }
    }

    private static void readWhile2(FileInputStream in) throws IOException {
        int readData; // 表示读取到的字节值
        while ((readData = in.read()) != -1) {
            // 不等于-1 进入while do sth
            System.out.print(((char) readData));

        }
    }

    private static void readWhile1(FileInputStream in) throws IOException {
        while (true) {
            int readData = in.read();
            if (readData == -1) {
                // 文件末尾
                break;
            }
            System.out.print(((char) readData));
        }
    }
}
